package com.metagurukul.informer.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import junit.framework.TestCase;
import com.metagurukul.informer.dao.TagDAO;
import com.metagurukul.informer.utility.ConnectionFactory;
import com.metagurukul.informer.valueObjects.Questions;
import com.metagurukul.informer.valueObjects.Tags;

public class TagSearchServiceTest extends TestCase{
    
	String testTagName="testTag";
	int testTagid;
	@Override
	protected void setUp() throws Exception {
		try {
			TagDAO tagDAO = new TagDAO();
			testTagid= tagDAO.findTagId(testTagName);
		} catch (Exception ex) {
			assertNull(ex);
		}
	}

	
	public void testfindTagName() {
		try {
			TagSearchService tagSearchService = new TagSearchService();
			String name=tagSearchService.findTagName(testTagid);
			assertEquals(testTagName, name);
		} catch (Exception ex) {
			assertNull(ex);
		}
	}
	
	public void testQuestionList() {
		try {
			TagSearchService tagSearchService = new TagSearchService(testTagid);
			List<Questions> questions=tagSearchService.questionList();
			//assertEquals(testTagName , name);
		} catch (Exception ex) {
			assertNull(ex);
		}
	}

	public void testSearchTags() {
		try {
			TagSearchService tagSearchService = new TagSearchService();
			List<Tags> questions=tagSearchService.searchTags(testTagid);
			//assertEquals(testTagName , name);
		} catch (Exception ex) {
			assertNull(ex);
		}
	}
	
	@Override
	protected void tearDown() throws Exception {
		try {
			Connection con=ConnectionFactory.getInstance();
			String sql = "DELETE FROM tags WHERE id=?";
			PreparedStatement ps = null;
			ps = con.prepareStatement(sql);
			ps.setInt(1,testTagid);
			ps.executeUpdate();
		} catch (Exception ex) {
			assertNull(ex);
		}
	}
}


